package com.zshy.base.core.contract.exception;

import com.zshy.base.core.contract.enums.IEnum;
import com.zshy.base.core.contract.enums.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * 业务告警异常，分级别处理
 *
 * @author zhouhengzhe
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ServiceErrorException extends RuntimeException  implements Serializable {

    private final Integer code;

    private final String message;

    public ServiceErrorException() {
        this(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc());
    }

    public ServiceErrorException(String message) {
        this(ResultCodeEnum.FAIL.getCode(), message);
    }

    public ServiceErrorException(Integer code, String message) {
        this.message = message;
        this.code = code;
    }

    public ServiceErrorException(Throwable e) {
        this(e.getMessage());
    }

    public ServiceErrorException(IEnum<Integer> resultCode) {
        this(resultCode.getCode(), resultCode.getDesc());
    }

}
